package com.uzhie.jt808.msg.entity.JT_200;

import org.apache.log4j.Logger;

import java.nio.ByteBuffer;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by TangFei on 2018/10/6.
 * 苏标 报警
 */
public abstract class JS_SuperWarn implements JS_Warn {

    protected Logger logger = Logger.getLogger(getClass());
    protected ByteBuffer buffer;

    protected int latitude;
    protected int longitude;
    protected String time;

    protected String readBCDTime() {
        return (new StringBuilder("20")).append(String.format("%02X", buffer.get())).append("-")
                .append(String.format("%02X", buffer.get())).append("-")
                .append(String.format("%02X", buffer.get())).append(" ")
                .append(String.format("%02X", buffer.get())).append(":")
                .append(String.format("%02X", buffer.get())).append(":")
                .append(String.format("%02X", buffer.get())).toString();
    }

    protected abstract void ReadFromBytes();

    @Override
    public void ReadFromBytes(byte[] bytes) {
        buffer = ByteBuffer.wrap(bytes);
        ReadFromBytes();
    }

    public double getLatitude() {
        return latitude / 1000000D;
    }

    public double getLongitude() {
        return longitude / 1000000D;
    }

    public Date getTime() {
        DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            return format.parse(time);
        } catch (ParseException e) {
            e.printStackTrace();
            return new Date(0L);
        }
    }
}
